package com.example.administrator.caigou51.activity;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.alipay.sdk.app.PayTask;
import com.example.administrator.caigou51.EventBusClass.GotoFragment;
import com.example.administrator.caigou51.EventBusClass.JpushCurrentMessageActivity;
import com.example.administrator.caigou51.R;
import com.example.administrator.caigou51.alibabaPay.PayResult;
import com.example.administrator.caigou51.alibabaPay.SignUtils;
import com.example.administrator.caigou51.bean.AccountBean;
import com.example.administrator.caigou51.bean.AlibabaOrderInfo;
import com.example.administrator.caigou51.bean.MainDataBean;
import com.example.administrator.caigou51.bean.PayBean;
import com.example.administrator.caigou51.bean.PayTypeBean;
import com.example.administrator.caigou51.bean.WeXinPaySuccess;
import com.example.administrator.caigou51.bean.WeiXinOrderInfo;
import com.example.administrator.caigou51.global.App;
import com.example.administrator.caigou51.global.Constant;
import com.example.administrator.caigou51.request.BaseResponse;
import com.example.administrator.caigou51.request.ICallBackForRequestServer;
import com.example.administrator.caigou51.request.RequestServerManager;
import com.example.administrator.caigou51.util.ToastUtil;
import com.example.administrator.caigou51.widget.dialog.SweetDialogManager;
import com.example.administrator.caigou51.wxapi.WXPayEntryActivity;
import com.tencent.mm.sdk.modelpay.PayReq;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.WXAPIFactory;
import com.umeng.analytics.MobclickAgent;

import java.io.Serializable;
import java.net.URLEncoder;
import java.util.List;

import cn.pedant.SweetAlert.SweetAlertDialog;
import de.greenrobot.event.EventBus;

/**
 * Created by Administrator on 2016/8/31/031.
 */
public class PayMoneyActivity  extends GBaseActivity {
    private RelativeLayout relativeLayoutWXZF;
    private ImageView imageViewWX;
    private TextView textViewWX;
    private TextView textViewWXAQ;
    private View viewWeiXin;
    private RelativeLayout relativeLayoutZFBZF;
    private ImageView imageViewZFB;
    private TextView textViewZFB;
    private TextView textViewZFBQ;
    private View viewZhiFuBao;
    private RelativeLayout relativeLayoutZZZF;
    private ImageView imageViewZZZF;
    private TextView textViewZZZF;
    private TextView textViewZZZFQ;
    private View viewZhuangZhangZhiFu;
    private RelativeLayout relativeLayoutHDFK;
    private ImageView imageViewhdfk;
    private TextView textViewhdfk;
    private TextView textViewhdfkQ,textViewMoney;
    private View viewHuoDaoFuKuang;


    private final String TypeWeiXin="weixin_pay";
    private final String TypeZhiFuBao="alipay";
    private final String TypeZhuangZhang="transfer";
    private final String TypeHuoDaoFuKuang="COD";


    public static String TagPayBean="TagPayBean";
    public static String TagAccountBean="TagAcountBean";
    private PayBean payBean;
    private AccountBean accountBean;
    private static final int SDK_PAY_FLAG = 1;
    private static final int SDK_CHECK_FLAG = 2;
    private String payTypeIdWeiXin = "";
    private String payTypeIdZhiFuBao = "";
    private String payTypeIdZhuangZhang = "";
    private String payTypeIdHuoDaoFuKuang = "";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.setContentViewFor720_1280(R.layout.activity_pay_money);
        findViewByIds();
        initDatas();
        TaskGetMainData(false);
    }

    private void findViewByIds() {
        relativeLayoutWXZF = (RelativeLayout) findViewById(R.id.relativeLayoutWXZF);relativeLayoutWXZF.setOnClickListener(this);
        imageViewWX = (ImageView) findViewById(R.id.imageViewWX);
        textViewWX = (TextView) findViewById(R.id.textViewWX);
        textViewWXAQ = (TextView) findViewById(R.id.textViewWXAQ);
        viewWeiXin = (View) findViewById(R.id.ViewWeiXin);
        relativeLayoutZFBZF = (RelativeLayout) findViewById(R.id.relativeLayoutZFBZF);relativeLayoutZFBZF.setOnClickListener(this);
        imageViewZFB = (ImageView) findViewById(R.id.imageViewZFB);
        textViewZFB = (TextView) findViewById(R.id.textViewZFB);
        textViewZFBQ = (TextView) findViewById(R.id.textViewZFBQ);
        viewZhiFuBao = (View) findViewById(R.id.ViewZhiFuBao);
        relativeLayoutZZZF = (RelativeLayout) findViewById(R.id.relativeLayoutZZZF);relativeLayoutZZZF.setOnClickListener(this);
        imageViewZZZF = (ImageView) findViewById(R.id.imageViewZZZF);
        textViewZZZF = (TextView) findViewById(R.id.textViewZZZF);
        textViewZZZFQ = (TextView) findViewById(R.id.textViewZZZFQ);
        viewZhuangZhangZhiFu = (View) findViewById(R.id.ViewZhuangZhangZhiFu);
        relativeLayoutHDFK = (RelativeLayout) findViewById(R.id.relativeLayoutHDFK);relativeLayoutHDFK.setOnClickListener(this);
        imageViewhdfk = (ImageView) findViewById(R.id.imageViewhdfk);
        textViewhdfk = (TextView) findViewById(R.id.textViewhdfk);
        textViewhdfkQ = (TextView) findViewById(R.id.textViewhdfkQ);
        textViewMoney=(TextView)findViewById(R.id.textViewMoney);
        viewHuoDaoFuKuang = (View) findViewById(R.id.ViewHuoDaoFuKuang);

        relativeLayoutWXZF.setVisibility(View.GONE);
        viewWeiXin.setVisibility(View.GONE);
        relativeLayoutZFBZF.setVisibility(View.GONE);
        viewZhiFuBao.setVisibility(View.GONE);
        relativeLayoutZZZF.setVisibility(View.GONE);
        viewZhuangZhangZhiFu.setVisibility(View.GONE);
        relativeLayoutHDFK.setVisibility(View.GONE);
        viewHuoDaoFuKuang.setVisibility(View.GONE);
    }
    private void initDatas() {

        setTopTitle("收银台");
        EventBus.getDefault().register(this);
        payBean= (PayBean) getIntent().getSerializableExtra(TagPayBean);
        textViewMoney.setText("￥"+payBean.getPay_amount());
    }
    private void fillArrayInListView(List<PayTypeBean> payTypeBeanList) {
        for (int i=0;i<payTypeBeanList.size();i++)
        {
            if (payTypeBeanList.get(i).getPayment_code().equals(TypeWeiXin))
            {
                relativeLayoutWXZF.setVisibility(View.VISIBLE);
                viewWeiXin.setVisibility(View.VISIBLE);

            }else if (payTypeBeanList.get(i).getPayment_code().equals(TypeZhiFuBao))
            {
                relativeLayoutZFBZF.setVisibility(View.VISIBLE);
                viewZhiFuBao.setVisibility(View.VISIBLE);
            }else if (payTypeBeanList.get(i).getPayment_code().equals(TypeZhuangZhang))
            {
                relativeLayoutZZZF.setVisibility(View.VISIBLE);
                viewZhuangZhangZhiFu.setVisibility(View.VISIBLE);
            }else if (payTypeBeanList.get(i).getPayment_code().equals(TypeHuoDaoFuKuang))
            {
                relativeLayoutHDFK.setVisibility(View.VISIBLE);
                viewHuoDaoFuKuang.setVisibility(View.VISIBLE);
            }
        }
    }
    private void setPayBeenId(List<PayTypeBean> payTypeBeanList) {
        for (int i=0;i<payTypeBeanList.size();i++)
        {
            if (payTypeBeanList.get(i).getPayment_code().equals(TypeWeiXin))
            {
                relativeLayoutWXZF.setVisibility(View.VISIBLE);
                viewWeiXin.setVisibility(View.VISIBLE);
                payTypeIdWeiXin = payTypeBeanList.get(i).getPayment_id()+"";
            }else if (payTypeBeanList.get(i).getPayment_code().equals(TypeZhiFuBao))
            {
                relativeLayoutZFBZF.setVisibility(View.VISIBLE);
                viewZhiFuBao.setVisibility(View.VISIBLE);
                payTypeIdZhiFuBao= payTypeBeanList.get(i).getPayment_id()+"";
            }else if (payTypeBeanList.get(i).getPayment_code().equals(TypeZhuangZhang))
            {
                relativeLayoutZZZF.setVisibility(View.VISIBLE);
                viewZhuangZhangZhiFu.setVisibility(View.VISIBLE);
                payTypeIdZhuangZhang= payTypeBeanList.get(i).getPayment_id()+"";
                if (payTypeBeanList.get(i).getPayment_account()!=null && payTypeBeanList.get(i).getPayment_account().size()>0) {
                    accountBean = JSON.parseObject(payTypeBeanList.get(i).getPayment_account().get(0).toString(), AccountBean.class);
                }
            }else if (payTypeBeanList.get(i).getPayment_code().equals(TypeHuoDaoFuKuang))
            {
                relativeLayoutHDFK.setVisibility(View.VISIBLE);
                viewHuoDaoFuKuang.setVisibility(View.VISIBLE);
                payTypeIdHuoDaoFuKuang= payTypeBeanList.get(i).getPayment_id()+"";
            }
        }
    }

    private void TaskGetMainData(final boolean isloadmore) {
        RequestServerManager.getInstanceDIY().handleMethodDIY((GBaseActivity) getActivity(), null, isloadmore, null,
                Constant.getRootUrl() + Constant.Action.Action_PayType, Constant.Action.Action_PayType, RequestServerManager.getInstanceDIY().
                        getRequestParams(Constant.Action.Action_PayType), BaseResponse.class, new ICallBackForRequestServer<BaseResponse>() {
                    @Override
                    public void onSuccess(BaseResponse result) {
                        // JSONObject jsonObject = (JSONObject) result.getData();
                      List<PayTypeBean>  payTypeBeanList = JSON.parseArray(result.getData().toString(), PayTypeBean.class);
                        fillArrayInListView(payTypeBeanList);
                        setPayBeenId(payTypeBeanList);

                    }

                    @Override
                    public void onFail(int type, String errorMsg, String json) {

                    }
                });
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId())
        {
            case R.id.relativeLayoutWXZF:
                payBean.setPayment_id(payTypeIdWeiXin);
                TaskIsHuiYuan(false);
                break;
            case R.id.relativeLayoutZFBZF:
                payBean.setPayment_id(payTypeIdZhiFuBao);
                TaskPayZhiFuBao(false);

                break;
            case R.id.relativeLayoutZZZF:
                payBean.setPayment_id(payTypeIdZhuangZhang);
                Intent intetn =new Intent(PayMoneyActivity.this,ZhuanZhangPayActivity.class);
                intetn.putExtra(PayMoneyActivity.TagPayBean, (Serializable) payBean);
                intetn.putExtra(PayMoneyActivity.TagAccountBean, (Serializable) accountBean);
                startActivity(intetn);
                break;
            case R.id.relativeLayoutHDFK:
                SweetDialogManager.getInstance().showDialogByWarmTitleText(this, "确认要货到付款吗?", "", false, false, new SweetAlertDialog.OnSweetClickListener() {
                    @Override
                    public void onClick(SweetAlertDialog sweetAlertDialog) {
                        sweetAlertDialog.dismiss();

                    }
                }, new SweetAlertDialog.OnSweetClickListener() {
                    @Override
                    public void onClick(SweetAlertDialog sweetAlertDialog) {
                        sweetAlertDialog.dismiss();
                        payBean.setPayment_id(payTypeIdHuoDaoFuKuang);
                        TaskHuoDaoFuKuangSumit(false);
                    }
                });

                break;
        }
    }

    public static void sendPayReq(WeiXinOrderInfo result, IWXAPI api) {


        PayReq req = new PayReq();
        //服务端返回的参数
        req.appId = result.getAppid();
        req.partnerId = result.getPartnerid();
        req.prepayId = result.getPrepayid();
        req.nonceStr = result.getNoncestr();
        req.timeStamp = result.getTimestamp();
     //   req.packageValue = "Sign=WXPay";
        req.packageValue =result.getPackages();
        req.sign = result.getSign();
        // 在支付之前，如果应用没有注册到微信，应该先调用IWXMsg.registerApp将应用注册到微信
        api.sendReq(req);
    }
    public void TaskIsHuiYuan(final boolean isloadmore) {
        RequestServerManager.getInstanceDIY().handleMethodDIY(null, null, isloadmore, null,
                Constant.getRootUrl() + Constant.Action.Action_PayWeiXin, Constant.Action.Action_PayWeiXin, RequestServerManager.getInstanceDIY().
                        getRequestParams(Constant.Action.Action_PayWeiXin, App.getUserBean().getUserid(),App.getUserBean().getSession_id(),payBean.getOrder_id()), BaseResponse.class, new ICallBackForRequestServer<BaseResponse>() {
                    @Override
                    public void onSuccess(BaseResponse result) {
                      //  ToastUtil.showToast(result.getMessage());
                        // api = WXAPIFactory.createWXAPI((GBaseActivity)mContext, Constant.SystemContext.WXID, true);
                        WeiXinOrderInfo weiXinOrderInfo = JSON.parseObject(result.getData().toString(), WeiXinOrderInfo.class);
                        IWXAPI api = WXAPIFactory.createWXAPI(PayMoneyActivity.this, null);
                        api.registerApp(Constant.SystemContext.WXID);
                        //  WeiXinPayBean weiXinPayBean = JSON.parseObject(JSON.toJSONString(result.getRetval()), WeiXinPayBean.class);
                         sendPayReq(weiXinOrderInfo, api);

                    }

                    @Override
                    public void onFail(int type, String errorMsg, String json) {
                        WXPayEntryActivity.OrderId = payBean.getOrder_id();
                    }
                });
    }



    private void TaskPayZhiFuBao(final boolean isloadmore) {
        RequestServerManager.getInstanceDIY().handleMethodDIY((GBaseActivity) getActivity(), null, isloadmore, null,
                Constant.getRootUrl() + Constant.Action.Action_PayZhiFuBao, Constant.Action.Action_PayZhiFuBao, RequestServerManager.getInstanceDIY().
                        getRequestParams(Constant.Action.Action_PayZhiFuBao, App.getUserBean().getUserid(),App.getUserBean().getSession_id(),payBean.getOrder_id()), BaseResponse.class, new ICallBackForRequestServer<BaseResponse>() {
                    @Override
                    public void onSuccess(BaseResponse result) {
                        // JSONObject jsonObject = (JSONObject) result.getData();
                        AlibabaOrderInfo  alibabaOrderInfo = JSON.parseObject(result.getData().toString(), AlibabaOrderInfo.class);
                       // fillArrayInListView(payTypeBeanList);
                        pay(alibabaOrderInfo);
                    }

                    @Override
                    public void onFail(int type, String errorMsg, String json) {

                    }
                });
    }


    public void pay(AlibabaOrderInfo alibabaOrderInfo) {
        if (TextUtils.isEmpty(alibabaOrderInfo.getPartner()) || TextUtils.isEmpty(alibabaOrderInfo.getPrivatekey())
                || TextUtils.isEmpty(alibabaOrderInfo.getSeller_id())) {

            new AlertDialog.Builder(this)
                    .setTitle("警告")
                    .setMessage("需要配置PARTNER | RSA_PRIVATE| SELLER")
                    .setPositiveButton("确定",
                            new DialogInterface.OnClickListener() {
                                public void onClick(
                                        DialogInterface dialoginterface, int i) {
                                    //
                                    finish();
                                }
                            }).show();
            return;
        }
        // 订单
        String orderInfo = getOrderInfo(alibabaOrderInfo);

        // 对订单做RSA 签名
        String sign = sign(orderInfo, alibabaOrderInfo);
        try {
            // 仅需对sign 做URL编码
            sign = URLEncoder.encode(sign, "UTF-8");
            //sign="partner='2088601052577326'&seller_id='kzj_china@126.com'&out_trade_no='103010051362042'&subject='测试的商品'&body='该测试商品的详细描述'&total_fee='0.01'&notify_url='http://www.baidu.com'&service='mobile.securitypay.pay'&payment_type='1'&_input_charset='utf-8'&it_b_pay='30m'&return_url='m.alipay.com'";

        } catch (Exception e) {
            e.printStackTrace();
        }

        // 完整的符合支付宝参数规范的订单信息
        final String payInfo = orderInfo + "&sign=\"" + sign + "\"&"
                + getSignType();

        Runnable payRunnable = new Runnable() {

            @Override
            public void run() {
                // 构造PayTask 对象
                PayTask alipay = new PayTask(PayMoneyActivity.this);
                // 调用支付接口，获取支付结果
                String result = alipay.pay(payInfo);

                Message msg = new Message();
                msg.what = SDK_PAY_FLAG;
                msg.obj = result;
                mHandler.sendMessage(msg);
            }
        };

        // 必须异步调用
        Thread payThread = new Thread(payRunnable);
        payThread.start();
    }
    public String sign(String content, AlibabaOrderInfo alibabaOrderInfo2) {
        return SignUtils.sign(content, alibabaOrderInfo2.getPrivatekey());
    }
    public String getSignType() {
        return "sign_type=\"RSA\"";
    }
    public String getOrderInfo(AlibabaOrderInfo alibabaOrderInfo) {

        // 签约合作者身份ID
        String orderInfo = "partner=" + "\"" + alibabaOrderInfo.getPartner() + "\"";

        // 签约卖家支付宝账号
        orderInfo += "&seller_id=" + "\"" + alibabaOrderInfo.getSeller_id() + "\"";

        // 商户网站唯一订单号
        orderInfo += "&out_trade_no=" + "\"" + alibabaOrderInfo.getOut_trade_no() + "\"";

        // 商品名称
        orderInfo += "&subject=" + "\"" + alibabaOrderInfo.getSubject() + "\"";

        // 商品详情
        orderInfo += "&body=" + "\"" + alibabaOrderInfo.getSubject() + "\"";

        // 商品金额
        orderInfo += "&total_fee=" + "\"" + alibabaOrderInfo.getTotal_fee() + "\"";

        // 服务器异步通知页面路径
        orderInfo += "&notify_url=" + "\"" + alibabaOrderInfo.getNotify_url()
                + "\"";

        // 服务接口名称， 固定值
        orderInfo += "&service=\"mobile.securitypay.pay\"";

        // 支付类型， 固定值
        orderInfo += "&payment_type=\"1\"";

        // 参数编码， 固定值
        orderInfo += "&_input_charset=\"utf-8\"";

        // 设置未付款交易的超时时间
        // 默认30分钟，一旦超时，该笔交易就会自动被关闭。
        // 取值范围：1m～15d。
        // m-分钟，h-小时，d-天，1c-当天（无论交易何时创建，都在0点关闭）。
        // 该参数数值不接受小数点，如1.5h，可转换为90m。
        orderInfo += "&it_b_pay=\"30m\"";

        // extern_token为经过快登授权获取到的alipay_open_id,带上此参数用户将使用授权的账户进行支付
        // orderInfo += "&extern_token=" + "\"" + extern_token + "\"";

        // 支付宝处理完请求后，当前页面跳转到商户指定页面的路径，可空
        orderInfo += "&return_url=\"m.alipay.com\"";

        // 调用银行卡支付，需配置此参数，参与签名， 固定值 （需要签约《无线银行卡快捷支付》才能使用）
        // orderInfo += "&paymethod=\"expressGateway\"";

        return orderInfo;
    }
    public void onEventMainThread(WeXinPaySuccess weXinPaySuccess) {
        App.getInstance().showToast("支付成功");
        Intent intent = new Intent(PayMoneyActivity.this, TradeSuccessActivity.class);
        intent.putExtra("order_id", payBean.getOrder_id());
        intent.putExtra(TradeSuccessActivity.TagPayStyle,"微信支付");
        intent.putExtra(TradeSuccessActivity.TagPayTotal,payBean.getPay_amount()+"");
        intent.putExtra(TradeSuccessActivity.TagPayTips,"付款成功啦！");
        setResult(RESULT_OK);
        startActivity(intent);
        PayMoneyActivity.this.finish();
        //友盟自定义事件，支付成功
        MobclickAgent.onEvent(getActivity(),"zfbPaySuccess");
    }
    private Handler mHandler = new Handler() {
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case SDK_PAY_FLAG: {
                    PayResult payResult = new PayResult((String) msg.obj);

                    // 支付宝返回此次支付结果及加签，建议对支付宝签名信息拿签约时支付宝提供的公钥做验签
                    String resultInfo = payResult.getResult();

                    String resultStatus = payResult.getResultStatus();

                    // 判断resultStatus 为“9000”则代表支付成功，具体状态码代表含义可参考接口文档
                    if (TextUtils.equals(resultStatus, "9000")) {
                        App.getInstance().showToast("支付成功");
                        Intent intent = new Intent(PayMoneyActivity.this, TradeSuccessActivity.class);
                        intent.putExtra("order_id", payBean.getOrder_id());
                        intent.putExtra(TradeSuccessActivity.TagPayStyle,"支付宝");
                        intent.putExtra(TradeSuccessActivity.TagPayTotal,payBean.getPay_amount()+"");
                        intent.putExtra(TradeSuccessActivity.TagPayTips,"付款成功啦！");
                        setResult(RESULT_OK);
                        startActivity(intent);
                        PayMoneyActivity.this.finish();
                        //友盟自定义事件，支付成功
                        MobclickAgent.onEvent(getActivity(),"zfbPaySuccess");
                    } else {
                        // 判断resultStatus 为非“9000”则代表可能支付失败
                        // “8000”代表支付结果因为支付渠道原因或者系统原因还在等待支付结果确认，最终交易是否成功以服务端异步通知为准（小概率状态）
                        if (TextUtils.equals(resultStatus, "8000")) {
                            App.getInstance().showToast("支付结果确认中");
                        } else {
                            // 其他值就可以判断为支付失败，包括用户主动取消支付，或者系统返回的错误
                            App.getInstance().showToast("支付失败");
                            MobclickAgent.onEvent(getActivity(),"zfbPayFail");

                        }
                    }
                    break;
                }
                case SDK_CHECK_FLAG: {
                    App.getInstance().showToast("检查结果为：" + msg.obj);
                    MobclickAgent.onEvent(getActivity(),"zfbPayFail");
                    break;
                }
                default:
                    break;
            }
        }

        ;
    };


    private void TaskHuoDaoFuKuangSumit(final boolean isloadmore) {
        RequestServerManager.getInstanceDIY().handleMethodDIY((GBaseActivity) getActivity(), null, isloadmore, null,
                Constant.getRootUrl() + Constant.Action.Action_PayZhuangZhang, Constant.Action.Action_PayZhuangZhang, RequestServerManager.getInstanceDIY().
                        getRequestParams(Constant.Action.Action_PayZhuangZhang, App.getUserBean().getUserid(),App.getUserBean().getSession_id(),payBean.getOrder_id(),payBean.getPayment_id()), BaseResponse.class, new ICallBackForRequestServer<BaseResponse>() {
                    @Override
                    public void onSuccess(BaseResponse result) {
                        // JSONObject jsonObject = (JSONObject) result.getData();
                        //   List<PayTypeBean> payTypeBeanList = JSON.parseArray(result.getData().toString(), PayTypeBean.class);
                    /*    SweetDialogManager.getInstance().showDialogBySuccessTitleText(PayMoneyActivity.this, "下单成功！", "", false, false, new SweetAlertDialog.OnSweetClickListener() {
                            @Override
                            public void onClick(SweetAlertDialog sweetAlertDialog) {
                                Intent intent = new Intent(PayMoneyActivity.this, TradeSuccessActivity.class);
                                startActivity(intent);
                            }
                        });*/
                        Intent intent = new Intent(PayMoneyActivity.this, TradeSuccessActivity.class);
                        intent.putExtra(TradeSuccessActivity.TagPayStyle,"货到付款");
                        intent.putExtra(TradeSuccessActivity.TagPayTotal,payBean.getPay_amount()+"");
                        intent.putExtra(TradeSuccessActivity.TagPayTips,"订单提交成功！");
                        startActivity(intent);
                    }

                    @Override
                    public void onFail(int type, String errorMsg, String json) {

                    }
                });
    }

    @Override
    public void onBackPressed() {
        // public void showDialogByWarmTitleText(GBaseActivity activity, String titleText, String contentText, boolean cancelable, boolean touchOutSideToCancel, OnSweetClickListener cancelListener, OnSweetClickListener confirmListener) {
        SweetDialogManager.getInstance().showDialogByWarmTitleText(this, "确认要离开收银台", "", false, false, new SweetAlertDialog.OnSweetClickListener() {
            @Override
            public void onClick(SweetAlertDialog sweetAlertDialog) {
                sweetAlertDialog.dismiss();

            }
        }, new SweetAlertDialog.OnSweetClickListener() {
            @Override
            public void onClick(SweetAlertDialog sweetAlertDialog) {
                sweetAlertDialog.dismiss();
                startActivity(new Intent(PayMoneyActivity.this, MainActivity.class));
                EventBus.getDefault().post(new GotoFragment(MainActivity.TAB_ShouYe));
                finish();
            }
        });


    }

    @Override
    public void doClickLeftImg() {
        onBackPressed();
    }
}